#include<stdio.h>
#include <string.h>
int zhuanhuan(char c);
int main(){
    char str[100];
    scanf("%s",str);
    int len=strlen(str);
    long long sum=0;
    long long count=1;
    for(int i=len-1;i>=0;i--){
        sum=sum+(zhuanhuan(str[i]))*count;
        count=count*16;
    }
    printf("%lld",sum);
    return 0; 
}
int zhuanhuan(char c){
    if(c>='0'&&c<='9'){
        return c-'0';
    }
    else if(c>='A'&&c<='F'){
        return c-'A'+10;
    }
    else if(c>='a'&&c<='f'){
        return c-'a'+10;
    }
    return 0;
}